package com.git.hui.yinshua.api.model;

import lombok.Data;

import java.io.Serializable;


/**
 * @author YiHui
 * @date 2024/6/7
 */
@Data
public class PageReq implements Serializable {
    private static final long serialVersionUID = 256099044442291464L;
    private Integer page;
    private Integer size;
    private Integer start;

    public Integer getStart() {
        if (this.start != null && this.start > 0) {
            return this.start;
        }

        if (page == null || size == null) {
            return this.start;
        }

        return (page - 1) * size;
    }

    public void setPage(Integer page) {
        this.page = page;
        this.start = getStart();
    }

    public void setSize(Integer size) {
        this.size = size;
        this.start = getStart();
    }

    public void autoInitReq() {
        if (page == null) {
            setPage(1);
        }
        if (size == null) {
            setSize(20);
        }
    }
}
